<template>
  <view class="service">
    <view class="recommend">
      <view
        class="recommend-item"
        @click="onrecommend(index, item.value, item.id)"
        :class="{ red: activeIndex == index }"
        v-for="(item, index) in choice"
        :key="index"
      >
        {{ item.name }}
      </view>

     <!-- <view
        class="recommend-item"
       
        :class="{ red: activeIndex == index + 3 }"
        v-for="(v, index) in cate"
        :key="index + 3"
		 @click="onrecommend((index + 3), v ,'')"
      >
        {{ v.name + v.id }}
      </view> -->
    </view>

    <view class="content" v-if="good && good.length > 0">
      <view class="content-item" v-for="item in good" :key="item.id"  @click="
            goProductDetails(item.id)
          "> 
        <image :src="item.cover" mode="" class="neironga2"></image>
        <view class="name u-text2"> {{ item.title }} </view>
        <view class="number">
          <view class="large">
            <rich-text
              :nodes="$mUtil.priceBigSmall(item.sale_price||item.min_sale_price)"
            ></rich-text>
          </view>

          <view class="small">￥{{ item.market_price||item.min_market_price }}</view>
        </view>
        <view class="sell"> 已售{{ item.result_sale_num }}件 </view>
      </view>
    </view>
    <nodata v-else :config="{ top: 1, content: '暂无商品~' }"></nodata>
  </view>
</template>

<script>
export default {
  data() {
    return {
      choice: [
        {
          id: 1,
          name: "推荐",
          value: "recommend",
        },
        {
          id: 2,
          name: "热销",
          value: "hot",
        },
        {
          id: 3,
          name: "新品",
          value: "new",
        },
		
      ],
      activeIndex: -1,
	  isConcat: false // 是否合并数组
    };
  },
  props: {
    cate: {
      type: Array,
      default: [],
    },
    good: {
      type: Array,
      default: [],
    },
   isActive:{
	   type:Number,
	   default:0
   }
  },
  watch: {
	  cate(e){
	  this.activeIndex =-1	  
	  if(!this.isConcat) {
		  this.isConcat = true
		  this.choice = this.choice.concat(e)
	  }
	  },
   
  },
  onLoad() {
    this.activeIndex = this.initNum;
	
  },
  onReady() {
  },
  methods: {
	  goProductDetails(id){
		  uni.navigateTo({
			url: this.isActive==0?'/pages/product/goods/serviceGood?id='+id:'/pages/product/goods/goods?id='+id,
      });
	  },
    onrecommend(index, type, groupId) {
      this.activeIndex = index;
      this.$emit("typeChange", { type: type, groupId: groupId });
    },
  },
};
</script>

<style scoped lang="scss">
.content {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  padding: 30rpx;
  // background-color: #f5f5f5;
  .content-item {
    background-color: #ffffff;
    border-radius: 18rpx;
    overflow: hidden;
    margin-bottom: 30rpx;
    image {
      width: 336rpx;
      height: 336rpx;
      // background-color: red;
    }
    .number {
      display: flex;
      align-items: flex-end;
      padding: 0 30rpx;
      .large {
        color: #ed3d07;
        font-size: 36rpx;
        font-weight: 500;
        text {
          font-size: 36rpx;
          font-weight: Bold;
        }
      }
      .small {
        font-size: 22rpx;
        color: #999999;
        font-weight: 400;
        text-decoration: line-through;
        margin-left: 16rpx;
      }
    }
    .sell {
      padding: 0 30rpx;
      font-size: 22rpx;
      font-weight: 400;
      color: #999999;
      margin-bottom: 36rpx;
      margin-top: 8rpx;
    }
    .name {
      width: 276rpx;
	  height: 80rpx;
	  line-height: 40rpx;
      padding: 0 30rpx;

    }
  }
}
.recommend {
  display: flex;
  // background-color: #f5f5f5;
  overflow: scroll;
  white-space: nowrap;
  border-radius: 40rpx 40rpx 0 0;
  .recommend-item {
    font-weight: 500;
    padding: 15rpx 30rpx;
    background-color: #ECECEC;
    margin: 40rpx 0 30rpx 30rpx;
    border-radius: 34rpx;
	color: #474747;
  }
  .red {
    background: #FF721B;
    color: #ffffff;
  }
}
</style>
